package com.demo.shufflingpicture;


import java.util.LinkedList;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class YunDongQuanActivity extends Activity {
	private ShufflingPicture shufflingPicture;
	private LinkedList<View> views;
	private LayoutInflater mInflater; // 用于解XML
	private LinearLayout mGallery;
	private int[] mImgIds;
	private TextView textView;
	//图片资源
	private int[] strings = new int[]{R.drawable.image_4,R.drawable.image_5,R.drawable.image_1};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.yundongquan_main);
		textView = (TextView) findViewById(R.id.tv3);
		//mInflater = LayoutInflater.from(this);
		initData();
		initView();
	//	initView2();
		textView.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Toast.makeText(YunDongQuanActivity.this,"点我干嘛！！",Toast.LENGTH_SHORT).show();
			}
		});
	}
	private void initData()
	{
		mImgIds = new int[]{ R.drawable.a, R.drawable.b, R.drawable.c,
				R.drawable.d, R.drawable.e, R.drawable.f, R.drawable.g,
				R.drawable.h, R.drawable.l,R.drawable.b};
	}
	private void initView() {
		mInflater = LayoutInflater.from(this);
		views = new LinkedList<View>();
		for(int i=0;i<strings.length;i++){
			ImageView view = (ImageView) mInflater.inflate(R.layout.imageview, null);
			view.setImageResource(strings[i]);
			view.setOnClickListener(new OnClickListener() {
				//图片点击可以跳转
				@Override
				public void onClick(View v) {
					Toast.makeText(YunDongQuanActivity.this,"傻逼吗！！！",Toast.LENGTH_SHORT).show();
					
				}
			});
			views.add(view);
		}
		shufflingPicture = (ShufflingPicture) findViewById(R.id.shuffling_picture);
		shufflingPicture.setViews(views);
		
		mGallery = (LinearLayout) findViewById(R.id.id_gallery);
		for (int i = 0; i < mImgIds.length; i++)
		{
			
			View view = mInflater.inflate(R.layout.activity_gallery_item,
					mGallery, false);
			ImageView img = (ImageView) view
					.findViewById(R.id.image1);
			img.setImageResource(mImgIds[i]);
			TextView txt1 = (TextView) view
					.findViewById(R.id.tv_1);
			TextView txt2 = (TextView) view
					.findViewById(R.id.tv_2);
			//显示文字
			txt1.setText("some info");
			txt2.setText("有100人已关注");
			view.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					Toast.makeText(YunDongQuanActivity.this,"傻逼吗",Toast.LENGTH_SHORT).show();
					
				}
			});
			mGallery.addView(view);
		}
	}
//	private void initView2()
//	{
//		//mInflater = LayoutInflater.from(this);
//		mGallery = (LinearLayout) findViewById(R.id.id_gallery);
//		for (int i = 0; i < mImgIds.length; i++)
//		{
//			
//			View view = mInflater.inflate(R.layout.activity_gallery_item,
//					mGallery, false);
//			ImageView img = (ImageView) view
//					.findViewById(R.id.image1);
//			img.setImageResource(mImgIds[i]);
//			TextView txt1 = (TextView) view
//					.findViewById(R.id.tv_1);
//			TextView txt2 = (TextView) view
//					.findViewById(R.id.tv_2);
//			//显示文字
//			txt1.setText("some info");
//			txt2.setText("有100人已关注");
//			view.setOnClickListener(new OnClickListener() {
//				
//				@Override
//				public void onClick(View v) {
//					Toast.makeText(YunDongQuanActivity.this,"傻逼吗",Toast.LENGTH_SHORT).show();
//					
//				}
//			});
//			mGallery.addView(view);
//		}
//	}

	
	
}
